package com.sangachy.stg;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Bullet {
	private Position orgPosition = null;
	private Position position = null;
	private float radius = 0;
	private float theta = 0;
	private float speed = 100;
	private byte status = 0;
	private boolean alive = true;
	private int type = 0;
	private float livingTime;
	
	private ShapeListener shape;
	
	private boolean inited = false;
	
	private float a = 0;
	
	public Bullet(Position position, float theta){
		this(position, theta,  0);
	}

	public Bullet(Position position, float theta, int type){
		this.orgPosition = new Position(position.x,position.y);
		this.position = new Position(position.x,position.y);
		this.theta = theta;
		this.radius = 0;
		this.inited = false;
		this.status = Constants.BULLET_UNBIRTH;
		this.type = type;
	}
	
//	public void setPosition(Position position){
//		this.position = position;
//	}
//	
//	public void setStatus(byte status){
//		this.status = status;
//	}
	
//	public byte getStatus(){
//		return status;
//	}
	
	public void update(float deltaTime){
		this.livingTime += deltaTime;

		this.theta = shape.updateTheta(livingTime,theta);
		this.a = shape.updateA(livingTime,a);
		this.radius = shape.updateRadius(a,theta);
		
//		this.radius += speed * deltaTime;
//		this.a += speed * deltaTime;
		
		this.position.x = this.orgPosition.x + (float)(this.radius * Math.cos(theta));
		this.position.y = this.orgPosition.y + (float)(this.radius * Math.sin(theta));
	}
	
	public void render(SpriteBatch spriteBatch){
		switch(type){
			case 0:{
				spriteBatch.draw(PictureManager.bullet1, position.x, position.y, 16, -16);
				break;
			}
			case 1:{
				spriteBatch.draw(PictureManager.bullet2, position.x, position.y, 16, -16);
				break;
			}
		}
	}
	
	public boolean isAlive(){
		return (position.x > 40 && position.x < 760 
				&& position.y > 40 && position.y < 440);
	}
	
	public ShapeListener getShape(){
		return this.shape;
	}
	
	public void setShape(ShapeListener shape){
		this.shape = shape;
	}
}
